<template>
  <BasicModal
    v-bind="$attrs"
    default-fullscreen
    @register="registerModal"
    title="代码预览"
    @ok="handleSubmit"
  >
    <a-tabs v-model:activeKey="currentFile" style="height: 100%">
      <a-tab-pane
        :key="index"
        :tab="item.fileName"
        v-for="(item, index) in files"
        style="height: 100%"
      >
        <MonacoEditor
          v-model:value="item.javaCode"
          :language="getLanguage(item)"
        />
      </a-tab-pane>
    </a-tabs>
  </BasicModal>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import { BasicModal, useModalInner } from '@/components/Modal';
import { preview } from '@/api/sys/dev/codeGenManager';
import { MonacoEditor } from '@/components/Monaco';

const currentFile = ref(0);
const files = ref<any>([]);
const [registerModal, { setModalProps }] = useModalInner(async (data) => {
  setModalProps({ confirmLoading: false });
  files.value = [];
  currentFile.value = 0;
  files.value = await preview(data.id);
  console.log(files.value, 'fff');
});

const getLanguage = (item) => {
  if (item.fileName.indexOf('java') > -1) return 'java';
  if (item.fileName.indexOf('ts') > -1) return 'typescript';
  if (item.fileName.indexOf('sql') > -1) return 'sql';
};
async function handleSubmit() {}
</script>
<style lang="less" scoped>
:deep(.ant-tabs-content) {
  height: 100%;
  .ant-tabs-tabpane {
    height: 100%;
    > div {
      height: 100%;
    }
  }
}
</style>
